package com.javen.study.vo;

import com.javen.study.enums.CommonEnums;
import lombok.Getter;

/**
 * @Author: tujw@netinnet.cn
 * @Date: 2022/11/18 16:06
 * @Description: 自定义统一响应实体
 */
@Getter
public class ResultVO<T> {
    /**
     * 状态码，比如1000代表响应成功
     */
    private Integer code;
    /**
     * 响应信息，用来说明响应情况
     */
    private String msg;
    /**
     * 响应的具体数据
     */
    private T data;

    public ResultVO(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResultVO success(T data) {
        return new ResultVO(1000, "success", data);
    }

    public static <T> ResultVO error(CommonEnums.ResultEnum resultEnum, T data) {
        return new ResultVO(resultEnum.getCode(), resultEnum.getMsg(), data);
    }

    public static <T> ResultVO customerError(String msg, T data) {
        return new ResultVO(9999, msg, data);
    }

}
